/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package codebar;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;

/**
 *
 * @author yole
 */
public class CodeNode implements Comparable {
    
    private ArrayList<String> nordem;
    private String year;

    public CodeNode(String year) {
        this.year = year;
        nordem = new ArrayList<String>();
    }
    
    public void sort() {
        Collections.sort(nordem);
    }
    
    public String getYear() {
        return year;
    }
    
    public String getNOrdem(int i) {
        return nordem.get(i);
    }
    
    public int size() {
        return nordem.size();
    }
    public void add(String nordem) throws DuplicatedDataException {
        if (!this.nordem.contains(nordem)) {
            this.nordem.add(nordem);
        } else throw new DuplicatedDataException();
    }
    @Override
    public int compareTo(Object t) {
        CodeNode n = (CodeNode)t;
        return Integer.valueOf(this.year) - Integer.valueOf(n.year);
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.year != null ? this.year.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final CodeNode other = (CodeNode) obj;
        if ((this.year == null) ? (other.year != null) : !this.year.equals(other.year)) {
            return false;
        }
        return true;
    }
    
    public void remove(String nordem) throws NotFoundException {
        if (this.nordem.contains(nordem))
            this.nordem.remove(nordem);
        else throw new NotFoundException();
    }
    
}
